﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using MOJsdk;

namespace MOJ
{
    /// <summary>
    /// Interaction logic for Control_SearchOrganizeSettings.xaml
    /// </summary>
    public partial class Control_SearchOrganizeSettings : UserControl
    {
        #region INICIALIZATION
        private IHost _host;
        public Control_SearchOrganizeSettings()
        {
            InitializeComponent();
            INI();
        }
        private void INI()
        {
            _host = GlobalVars.TheHost;

            INIVars();
            INIStyle();
            INIEvents();
        }
        private void INIVars()
        {
            if (!_host.SystemVars.VarExist("MoJFileBlackList"))
                _host.SystemVars.SetVar("MoJFileBlackList", "");


            if (!_host.SystemVars.VarExist("MoJMoviesBlackList"))
                _host.SystemVars.SetVar("MoJMoviesBlackList", "");

            if (!_host.SystemVars.VarExist("MoJFileIgnore"))
                _host.SystemVars.SetVar("MoJFileIgnore", "xvid;divx;x264;h264");
        }
        private void INIStyle()
        {
            _lbl_blacklist.Content = MOJLocalization.Localize("Movies Blacklist") + ": ";
            _lbl_movExt.Content = MOJLocalization.Localize("Movies Extensions") + ": ";
            _lbl_skiplist.Content = MOJLocalization.Localize("Files Blacklist") + ": ";
            _lbl_subExt.Content = MOJLocalization.Localize("Subtitles Extensions") + ": ";
            _lbl_ignore.Content = MOJLocalization.Localize("Ignored strings") + ": ";

            _btn_save.Content = MOJLocalization.Localize("Save");

            _txt_skiplist.Text = _host.SystemVars.GetVar("MoJFileBlackList");
            _txt_blacklist.Text = _host.SystemVars.GetVar("MoJMoviesBlackList");
            _txt_ignore.Text = _host.SystemVars.GetVar("MoJFileIgnore");
            _txt_movExt.Text = _host.SystemVars.GetVar("VideoType");
            _txt_subExt.Text = _host.SystemVars.GetVar("SubtitleType");

            _Grid.ApplyStyle("0101128");

            _lbl_blacklist.ApplyStyle("0101129");
            _lbl_movExt.ApplyStyle("0101130");
            _lbl_skiplist.ApplyStyle("0101131");
            _lbl_subExt.ApplyStyle("0101132");

            _txt_blacklist.ApplyStyle("0101133");
            _txt_movExt.ApplyStyle("0101134");
            _txt_skiplist.ApplyStyle("0101135");
            _txt_subExt.ApplyStyle("0101136");

            _btn_save.ApplyStyle("0101137");

            _lbl_ignore.ApplyStyle("0101138");
            _txt_ignore.ApplyStyle("0101139");
        }
        private void INIEvents()
        {
            _btn_save.Click += SaveSettings;
        }
        #endregion

        private void SaveSettings(object sender, RoutedEventArgs e)
        {
            _host.SystemVars.SetVar("MoJFileBlackList", _txt_skiplist.Text);
            _host.SystemVars.SetVar("MoJMoviesBlackList", _txt_blacklist.Text);
            _host.SystemVars.SetVar("VideoType", _txt_movExt.Text);
            _host.SystemVars.SetVar("SubtitleType", _txt_subExt.Text);
            _host.SystemVars.SetVar("MoJFileIgnore", _txt_ignore.Text);
        }
    }
}
